import { reqGetHospitalDetail } from '@/api/hospital/hospitalList';
import { ReqGetHospitalDetail } from '@/api/hospital/model/hospitalListTypes';
import { Badge, Button, Card, Descriptions } from 'antd'
import React, { useEffect, useState } from 'react'
import { useNavigate, useParams } from 'react-router-dom';

export default function HospitalDetail() {
  let {id} = useParams();
  //声明医院数据的状态
  let [hospital, setHospital] = useState<ReqGetHospitalDetail>();
  //解构赋值
  let hos = hospital?.hospital;
  let book = hospital?.bookingRule;
  //获取 navigate 函数
  let navigate = useNavigate();
  //发送 AJAX 请求
  useEffect(() => {
    let getHospital = async () => {
      //发送请求获取医院的详情数据
      let hospital = await reqGetHospitalDetail(id as string);
      //更新状态
      setHospital(hospital);
    }
    getHospital();
  }, [])
  return (
    <Card>
      <Descriptions title="基本信息" bordered>
        <Descriptions.Item style={{width: 150}} label="医院名称">{hos?.hosname}</Descriptions.Item>
        <Descriptions.Item label="医院 LOGO" span={2}><img width="50" src={hos?.logoData && 'data:image/png;base64,' + hos?.logoData} /></Descriptions.Item>
        <Descriptions.Item label="医院编码">{hos?.hoscode}</Descriptions.Item>
        <Descriptions.Item label="医院地址" span={2}>{hos?.param.fullAddress}</Descriptions.Item>
        <Descriptions.Item label="坐车路线" span={3}>
          {hos?.route}
        </Descriptions.Item>
        <Descriptions.Item label="医院简介" span={3}>
          {hos?.intro}
        </Descriptions.Item>
      </Descriptions>
      <div className="h-20"></div>
      <Descriptions title="预约规则信息" bordered>
        <Descriptions.Item label="预约周期">{book?.cycle}</Descriptions.Item>
        <Descriptions.Item label="放号时间" span={2}>{book?.releaseTime}</Descriptions.Item>
        <Descriptions.Item label="停挂时间">{book?.stopTime}</Descriptions.Item>
        <Descriptions.Item label="退号时间" span={2}>{book?.quitTime}</Descriptions.Item>
        <Descriptions.Item label="预约规则" span={3}>
          {book?.rule}
        </Descriptions.Item>
      </Descriptions>
      <div className="h-20"></div>
      <Button onClick={() => {
        navigate(-1);
      }}>返回</Button>
    </Card>
  )
}
